<div class="dialog dialog-changefy hidden">
    <div class="box" style="height:320px;">
        <div class="title">
            <h4 class="fl">更换房源对话框</h4>
            <span class="fr"><a href="#" onclick="closeDialog();">关闭</a></span>
        </div>
        <table class="form-tab">
            <tr>
                <th width="110">已分配房源：</th>
                <td>
                    <input disabled="disabled" name="house1" value="{$lottery.house_addr}" type="text" />
                </td>
            </tr>
            <tr>
                <th>换房依据：</th>
                <td>
                    <input placeholder="必填" name="reason" type="text" value="" />
                </td>
            </tr>
            <tr>
                <th>新房源地址：</th>
                <td>
                    <input placeholder="必填" name="house2" type="text" value="" />
                </td>
            </tr>
            <tr>
                <th>新房源租金：</th>
                <td>
                    <input name="zj2" type="text" disabled="disabled" />
                    <label>元/月</label>
                </td>
            </tr>
            <tr>
                <th></th>
                <td>租金从换房第2年开始按新房源租金收取</td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;line-height:40px;">
                    <button class="btn btn-highlight" onclick="action_DoChange();">提交</button>
                    <span>或</span>
                    <a href="#" onclick="closeDialog();" class="linkBtn">放弃</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<link type="text/css" href="__JS__/autocomplete2/src/jquery.autocomplete.min.css" rel="stylesheet">
<script src="__JS__/autocomplete2/src/jquery.autocomplete.js" type="text/javascript"></script>
<script>
    //disable所有自动填充字段；
    $(".disabled").attr("disabled", true);

    $('input[name=house2]').autocomplete({
        serviceUrl: '/admin/lottery/ajax_SearchHouseByAddr',
        extraParams: {house: $.trim($("input[name=house2]").val())},//动态参数值
        paramName: "house",//自定义的参数名 必须和extraParams 参数名相同
        showNoSuggestionNotice: true,
        noSuggestionNotice: '对不起，没有匹配到闲置的房源',
        onSelect: function (suggestion) {
            $("input[name=zj2]").val(suggestion.data.price);
        }
    });

    /* 签订合同 */
    function action_DoChange() {
        var id = $("input[name=id]").val();
        var reason = $("input[name=reason]").val();
        var house1 = $("input[name=house1]").val();
        var house2 = $("input[name=house2]").val();
        if(!reason){
            alert("请填写换房依据");
            $("input[name=reason]").focus();
            return false;
        }
        if(!house2){
            alert("请填写新房源地址");
            $("input[name=house2]").focus();
            return false;
        }
        $.ajax({
            url:"/admin/lottery/ajax_changefy",
            data: {id:id, reason:reason, house1:house1, house2:house2},
            type:"POST", dataType:"JSON",
            success: function(data){
                if(data.status){
                    alert("操作成功");
                    location.reload();
                }else{
                    console.log(data.info);
                    alert(data.info);
                }
            }
        });
    }

    /**
     * 打开办理入住手续对话框
     */
    function action_changefy() {

        $(".dialog-changefy").show();
    }

    /**
     * 关闭对话框
     */
    function closeDialog() {
        $(".dialog").hide();
    }
</script>
